package com.redis.controller;

import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping
public class RedisListController {

    @Resource
    private RedissonClient redissonClient;

    @RequestMapping("/list.json")
    public void redisString(){
        redissonClient.getBucket("aaa").set("bbbb",1,TimeUnit.MINUTES);

        RBucket<Object> rBucket = redissonClient.getBucket("aaa");
        rBucket.set("bbbb",1,TimeUnit.MINUTES);

        Object get = rBucket.get();
        System.out.println(get);

        //
        long size = rBucket.size();
        System.out.println(size);

        boolean compareAndSet = rBucket.compareAndSet("ccc", "ddd");

        System.out.println(compareAndSet);

        Object andSet = rBucket.getAndSet("eee");
        System.out.println(andSet);

        Object andDelete = rBucket.getAndDelete();
        System.out.println(andDelete);

    }


}
